﻿using ZR.Model.Souvenir;
using ZR.Model.Souvenir.Dto;
using ZR.Service.Souvenir.IService;

namespace ZR.Admin.WebApi.Controllers.Souvenir
{
    [Route(("souvenir/category"))]
    public class CategoryController : BaseController
    {
        private readonly ICategoryService _categoryService;

        public CategoryController(ICategoryService categoryService)
        {
            _categoryService = categoryService;
        }
        
        [HttpPost("addCategory")]
        public async Task<IActionResult> AddCategory([FromBody] Category category)
        {
            return SUCCESS(await _categoryService.InsertCategoryAsync(category) > 0);
        }

        [HttpPut("updateCategory")]
        public async Task<IActionResult> UpdateCategory([FromBody] Category category)
        {
            return SUCCESS(await _categoryService.UpdateCategoryAsync(category) > 0);
        }
        
        [HttpDelete("deleteCategory/{categoryId}")]
        public async Task<IActionResult> DeleteCategory(int categoryId)
        {
            return SUCCESS(await _categoryService.DeleteCategoryAsync(categoryId) > 0);
        }
        
        [HttpPost("getCategoryWithPage")]
        public async Task<IActionResult> GetCategoryWithPage([FromBody] CategoryQueryDto categoryQueryDto)
        {
            return SUCCESS(await _categoryService.SelectCategoryWithPageAsync(categoryQueryDto));
        }
        
        [HttpGet("getCategoryById/{categoryId}")]
        public async Task<IActionResult> GetCategoryById(int categoryId)
        {
            return SUCCESS(await _categoryService.SelectCategoryAsyncById(categoryId));
        }

        [HttpPost("getCategoryWithTree")]
        public async Task<IActionResult> GetCategoryWithTree()
        {
            return SUCCESS(await _categoryService.SelectCategoryWithTreeAsync());
        }
    }
}